<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在类中使用访问器</title>
</head>
<body>
    <script>
        class Request{
            constructor(url){
                this.data = {url}
            }
             
            set url(url){
                if(!/^https?:\/\//i.test(url)){
                    throw new Error("地址格式错误！");
                }
                this.data.url = url;
            }

            get url(){
                return this.data.url;
            }
        }

        let request = new Request("https://affsg.com");
        // request.url = "6789";
        console.log(request.url);
    </script>
</body>
</html>